$(function() {
	var shopData = {
		data: [
			{
				"premises_name":"泰安市奥林匹克花园小区",
				"building_num":"01",
				"unit":"01",
				"room_num":"101",
				"deposit_item_name":"装修押金2000",
				"deposit_item_price":"2000",
				"status":"未缴纳",
				"remark":"请业主尽快缴纳"
			},
			{
				"premises_name":"华新山水居",
				"building_num":"02",
				"unit":"02",
				"room_num":"202",
				"deposit_item_name":"装修押金5000",
				"deposit_item_price":"5000",
				"status":"已没收",
				"remark":"墙体损坏，本押金没收！"
			},
		]
	};
	function shopModal() {
		var self = this;

		self.defaults = {
			activeIndex: 0,
			isAdd: false,
			isAllcheck: false,
			isCancle: true,
			initData: {
				"premises_name":"华新000",
				"building_num":"00",
				"unit":"00",
				"room_num":"000",
				"deposit_item_name":"00000",
				"deposit_item_price":"00000",
				"status":"000",
				"remark":"000000000000000000"
			}
		}
		self.listData = ko.observableArray(shopData.data);

		self.line = ko.observable(self.defaults.initData);


		self.lineClick = function(data, e) {
			isHavePayButton(data);
			var lineData = $.extend({}, self.defaults.initData, data);
			self.line(lineData);
			var index = $(e.target).closest("li").index();

			self.defaults.activeIndex = index;
			self.defaults.isAdd = false;
		}
		
	}
	ko.applyBindings(new shopModal());
	
	$('#submit').click(function(){
		if(!$('#deposit_item_price').val()){
			UM.alert({
			    title: '未正确生成费用,无法缴纳！',
			    btnText: ["", "确定"],
			});
			return;
		}
		
		alert('OK');
		//可以进行费用的提交
	});
	
});

//如果客户的缴费状态为未缴费和无需缴纳，则将这张单据中的提交缴费按钮hidden掉，否则则取消hidden
function isHavePayButton(data) {
	var sta = data.status;
	//console.log(sta);
	if(sta == '未缴纳'){
		$('#submit').show();
	}else{
		$('#submit').hide();
	}
}

